<?php
namespace Admin\Model;
use Think\Model;

/**
* Created by hanquan.
* User Adminstrator
* Date Date 2017/3/27
* Time 00:01
* OptionModel 手机选项类
*/

class OptionModel extends Model
{
	private $Option = null;

	function __construct()
	{
		parent::__construct();
		$this->Option = M('Option');
	}

	/*
	* 获取选项列表
	*/
	public function get_option($cid){

		$condition['cid'] = $cid;
		return $this->Option->field('oid,o_label,o_price')->where($condition)->select();
	}

	/*
	* 获取选项价格
	*/
	public function get_option_price($oid){
		$condition['oid'] = $oid;
		return $this->Option->field('o_price')->where($condition)->find();
	}
	/**
     * 插入或修改选项
     * @data 提交选项的数据
     * @param $oid 选项id
     */
	public function set_option($data,$oid=FALSE){

		if(!$oid){
			return $this->Option->add($data);
		}else{
			$condition['oid'] = $oid;
			return $this->Option->where($condition)->save($data);
		}
	}

	/**
     * 删除选项
     * @param $oid 选项id
     */
	public function del_option($oid){
		
		$condition['oid'] = $oid;
		return $this->Option->where($condition)->delete();
	}
}